package com.softserveinc.autorent.manager;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import com.softserveinc.autorent.model.CarVendor;

@Stateless
//@TransactionManagement(TransactionManagementType.BEAN)
public class CarVendorEJB extends AbstractEJB<CarVendor> {

	@PersistenceContext(unitName = "jpa")
	private EntityManager em;

	@Override
	public EntityManager getEntityManager() {
		return em;
	}

	@Override
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}
	
	public CarVendorEJB() {
		super(CarVendor.class);
	}
/*@NamedQueries({
@NamedQuery(name = "CarVendor.findAll", query = "SELECT v FROM CarVendor v"),
@NamedQuery(name = "CarVendor.findById", query = "SELECT v FROM CarVendor v WHERE v.id = :id")
})*/	
	@Override
    public List<CarVendor> findAll() {
        TypedQuery<CarVendor> query = em.createNamedQuery("CarVendor.findAll", CarVendor.class);
        return query.getResultList();
    }
	
    public CarVendor findById(int id) {
    	
    	CarVendor vendor = new CarVendor();
        TypedQuery<CarVendor> query = em.createNamedQuery("CarVendor.findById", CarVendor.class);
        query.setParameter("id", id);
        if (query.getResultList().size() >= 1)
        	vendor  = query.getResultList().get(0);
        return vendor;
    }		

}
